home *** CD-ROM | disk | FTP | other *** search
- Path: atglab.bls.com!Alun.Champion
- From: Alun.Champion@bridge.bst.bls.com (Alun Champion)
- Newsgroups: comp.lang.c++
- Subject: Re: Template Class Linkage?
- Date: 09 Jan 1996 21:47:28 GMT
- Organization: Computer People Inc.
- Message-ID: <ALUN.CHAMPION.96Jan9164728@g7240065.bridge.bst.bls.com>
- References: <4cmnjs$mk7@mimsy.cs.umd.edu> <4ct9i4$i74@isoit109.bbn.hp.com>
- NNTP-Posting-Host: bstfirewall.bst.bls.com
- In-reply-to: Manfred_Lange's message of 9 Jan 1996 08:38:28 GMT
-
- In article <4ct9i4$i74@isoit109.bbn.hp.com> Manfred_Lange <Manfred_Lange@bbn.hp.com> writes:
-
- : gilman@cfar.umd.edu (Gil Carmel) wrote:
-
- :> I'm just learning templates, and I'm having problems with linkage.
- :> When the template class member function bodies are included in the ".h" file,
- :> everything is fine. But when the function bodies are in a separate ".c" file,
- :> calls to these functions from other files give an "undefined reference to
- :> function" error from the linker. Do template class member functions have
- :> to be in the ".h" file, or is this a problem with my compiler?
-
- :> [snipped]
-
- : My understanding is that the implementation of template classe member functions
- : need to be in a file which is NOT the cpp-file. Two approaches are taken
- : normally:
-
- : 1. Put the function bodies in the header file.
-
- : 2. Create a third file and include that one into the source files, where the
- : template is being used.
-
- : I personally prefer the first approach, although the second has the advantage
- : of separating the declaration from the implementation.
-
- This is all dependant on you compiler. Some compilers do template
- instantiation(sp?) at link time namely ptlink with the
- CenterLine compiler and HP compiler and others.
-
- It requires the template source code (in .c files) to reside in the same
- directory as the header, but does not need the source code available at compile
- time but establishes missing symbols after the initial link and tries
- to resolve these missing symbols by instantiating the necessary template
- functions.
-
- The problem with having the instantiation at compile time is you get
- code bloat where 2 different modules instantiate the same template,
- unless duplicate code removal is performed at the end.
-
- There are other template instantiation procedures and they are
- changing/improving all the time.
-
- Regards
-
- -A.
-
-
- --
- | A.Champion |
-